#include "data_flood.h"

void read_page(char *path, uint32 pageno, char *page_buf)
{
    FILE *fp =fopen(path, "rb");
    int offset = 0;

    if(!fp)
        df_error("Can not open %s for read:%m", path);
    
    fseek(fp, 0, SEEK_END);
    offset = ftell(fp);
    if(offset < (pageno + 1) * PAGE_SIZE) {
        df_log("File %s offset %lu expect %d", path, offset, (pageno + 1) * PAGE_SIZE);
        sleep(5);
        fseek(fp, SEEK_END, 0);
        offset = ftell(fp);
        df_error("File %s offset %d expect %lu", path, offset, (pageno + 1) * PAGE_SIZE);
    }
    fseek(fp, SEEK_SET, 0);

    if(PAGE_SIZE != fread(page_buf, 1, PAGE_SIZE, fp))
        df_error("read page error");
    fclose(fp);
}
